<template>
  <div class="add-node-btn-box">
    <div class="add-node-btn">
      <Popover v-model:visible="visible" class="" trigger="click" placement="rightTop">
        <template #content>
          <div class="add-node-popover-body">
            <a class="add-node-popover-item approver" @click="addType(1)">
              <div class="item-wrapper">
                <Icon size="20" icon="bxs:user" color="#ff943e" />
              </div>
              <p>审批人</p>
            </a>
            <a class="add-node-popover-item notifier" @click="addType(2)">
              <div class="item-wrapper">
                <Icon size="20" icon="ep:promotion" color="#3296fa" />
              </div>
              <p>抄送人</p>
            </a>
            <a class="add-node-popover-item condition" @click="addType(4)">
              <div class="item-wrapper">
                <Icon size="20" icon="icon-park-outline:branch-one" color="#15bc83" />
              </div>
              <p>条件分支</p>
            </a>
          </div>
        </template>
        <Button class="btn" shape="circle" type="primary" @click="visible = true">
          <template #icon><Icon icon="ant-design:plus-outlined" /></template>
        </Button>
      </Popover>
    </div>
  </div>
</template>
<script lang="tsx" setup name="AddNode">
  import { ref } from 'vue';
  import { Icon } from '/@/components/Icon';
  import { Button, Popover } from 'ant-design-vue';
  const props = defineProps<{
    childNode: any;
  }>();
  const emit = defineEmits(['update:childNode']);
  const visible = ref(false);
  const addType = (type: number) => {
    visible.value = false;
    if (type !== 4) {
      let data = {};
      if (type === 1) {
        data = {
          nodeName: '审核人',
          error: true,
          type: 1,
          settype: 1,
          selectMode: 0,
          selectRange: 0,
          directorLevel: 1,
          replaceByUp: 0,
          examineMode: 1,
          noHanderAction: 1,
          examineEndDirectorLevel: 0,
          childNode: props.childNode,
          nodeUserList: [],
        };
      } else if (type === 2) {
        data = {
          nodeName: '抄送人',
          type: 2,
          ccSelfSelectFlag: 1,
          childNode: props.childNode,
          nodeUserList: [],
        };
      }
      emit('update:childNode', data);
    } else {
      const data = {
        nodeName: '路由',
        type: 4,
        childNode: null,
        conditionNodes: [
          {
            nodeName: '条件1',
            error: true,
            type: 3,
            priorityLevel: 1,
            conditionList: [],
            nodeUserList: [],
            childNode: props.childNode,
          },
          {
            nodeName: '条件2',
            type: 3,
            priorityLevel: 2,
            conditionList: [],
            nodeUserList: [],
            childNode: null,
          },
        ],
      };
      emit('update:childNode', data);
    }
  };
</script>

<style lang="less" scoped>
  .add-node-btn-box {
    width: 240px;
    display: inline-flex;
    flex-shrink: 0;
    position: relative;

    &::before {
      content: '';
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      z-index: -1;
      margin: auto;
      width: 2px;
      height: 100%;
      background-color: #cacaca;
    }

    .add-node-btn {
      user-select: none;
      width: 240px;
      padding: 20px 0 32px;
      display: flex;
      -webkit-box-pack: center;
      justify-content: center;
      flex-shrink: 0;
      -webkit-box-flex: 1;
      flex-grow: 1;

      .btn {
        &:hover {
          transform: scale(1.3);
          box-shadow: 0 13px 27px 0 rgb(0 0 0 / 10%);
        }
      }
    }
  }

  .add-node-popover-body {
    max-width: 336px;

    .add-node-popover-item {
      display: inline-flex;
      align-items: center;
      cursor: pointer;
      color: #191f25 !important;
      margin-right: 8px;
      margin-bottom: 8px;
      width: 160px;
      background: rgba(17, 31, 44, 0.02);
      padding: 8px;
      border: 1px solid #ffffff;
      border-radius: 4px;

      .item-wrapper {
        user-select: none;
        display: flex;
        align-items: center;
        justify-content: center;
        width: 40px;
        height: 40px;
        background: #ffffff;
        border: 1px solid #eeeeee;
        border-radius: 16px;
        transition: all 0.3s cubic-bezier(0.645, 0.045, 0.355, 1);
        margin-right: 12px;
      }

      p {
        margin-bottom: 0;
      }

      &:hover {
        background: #ffffff;
        border: 1px solid #ecedef;
        box-shadow: 0 2px 8px 0 rgb(17 31 44 / 8%);
      }
    }

    .add-node-popover-item.auto .item-wrapper {
      color: #1059fb !important;
    }

    .add-node-popover-item:active .item-wrapper {
      box-shadow: none;
      background: #eaeaea;
    }
  }
</style>
